<template>
  <div>
    <el-table :data="tableData">
      <div style="margin: 15px 0;"></div>
      <el-table-column prop="goods.id" label="商品id"></el-table-column>
      <el-table-column prop="goods.name" label="商品名"></el-table-column>
      <el-table-column prop="goods.price" label="商品价格"></el-table-column>

      <el-table-column label="操作">
        <template #default="scope">
          <el-button @click="Delete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <br><br>
  </div>

</template>

<script>
import request from "@/utils/request";

export default {
  name: "ShoppingCar",
  data(){
    return{
      tableData:[
      ],
      readorder:false,
      goods: {},
      user: {},

    }
  },

  methods:{
    getCollection() {
      request.get("http://localhost:8087/Collection/ShowUserCollection").then(res => {
        if (res.flag) {
          this.tableData = res.data['collections']
          this.user = res.data['user']
          this.$message({
            type: 'success',
            message: res.msg
          });
        } else {
          this.$message.error(res.msg);
        }
      })
    },
    Delete(row){
      request.delete("http://localhost:8087/Collection/RemoveFromCollection?id="+row.goods.id).then(res => {
        if (res.flag) {
          this.$message({
            type: 'success',
            message: res.msg
          });
        } else {
          this.$message.error(res.msg);
        }
      })
    },
  },
  created(){
    this.getCollection()
  },
  ShowCollection(data){
    this.goods = data.goods
    this.readorder=true;
  },
}


</script>

<style scoped>
.div2{
  background-size: 100% ;
  float: left;
  margin-top: -200px;
}
.b3{
  margin-bottom: 20px;
}
.dialog1{
  z-index: 2;
}
</style>
